﻿using Common;
using gregn6Lib;
using NursingFormSystem.Common;
using NursingFormSystem.Model;
using SQLDLL;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace NursingFormSystem
{
    public partial class NursingFormPrint : Form
    {
        private GridppReport Report = new GridppReport();
        NurFormsService.NursingForm formService = new NurFormsService.NursingForm();
        string[] Patientinfo;
        string[] user;
        Tb_User LoginUser;
        ElectronicSignature es;
        public Tb_User InitLoginUser(string[] UserParam)
        {
            LoginUser = new Tb_User();
            LoginUser.UserId = UserParam[0];
            LoginUser.UserName = UserParam[1];
            LoginUser.DepartmentCode = UserParam[2];
            LoginUser.DepartmentName = UserParam[3];
            LoginUser.JobTitle = UserParam[4];
            LoginUser.PositionTitle = UserParam[5];
            return LoginUser;
        }

        public NursingFormPrint(string[] patientinfo, int FormId, string[] UserParm)
        {
            InitializeComponent();
            this.Patientinfo = patientinfo;
            this.user = UserParm;
            InitLoginUser(this.user);
            es = new ElectronicSignature(this.LoginUser);
            var ret = formService.GetNursingFormRecord(patientinfo[0], Convert.ToInt32(patientinfo[1]), FormId);
            if (ret.Code == 1)
            {
                NursingFormRecord record1 = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NursingFormRecord>>(ret.D)[0];
                AssessMent ps = XmlUtil.XMLToObject<AssessMent>(record1.NursingFormData, Encoding.UTF8);
                string image1 = "";
                string RYHS = ps.DieDaoYaChuangADLFengXianPingGu.RuYuanHuShiQianMing;
                if (!string.IsNullOrEmpty(RYHS))
                {
                    image1 = es.GetElectricSignBase64(record1.AreaId, ps.DieDaoYaChuangADLFengXianPingGu.RuYuanHuShiQianMing);
                }
                string image2 = "";
                string CYHS = ps.ChuYuanPingGu.ChuYuanHuShiQianMing;
                if (!string.IsNullOrEmpty(CYHS))
                {
                    image2 = es.GetElectricSignBase64(record1.AreaId, ps.ChuYuanPingGu.ChuYuanHuShiQianMing);
                }
                #region 跌倒墜床评估选项、压疮评估选项、ADL评估选项
                //跌倒墜床评估选项
                string strDieDaoPingGu = ps.DieDaoYaChuangADLFengXianPingGu.DieDaoPingGu;
                string[] ddpgArry = new string[2];
                if(!string.IsNullOrEmpty(strDieDaoPingGu)){
                    ddpgArry = strDieDaoPingGu.Split('#');
                }
                //压疮评估选项
                string strYaChuangPingGu = ps.DieDaoYaChuangADLFengXianPingGu.YaChuangPingGu;
                string[] ycpgArry = new string[5];
                if (!string.IsNullOrEmpty(strYaChuangPingGu))
                {
                    ycpgArry = strYaChuangPingGu.Split('#');
                }
                //ADL评估选项
                string strADLPingGu = ps.DieDaoYaChuangADLFengXianPingGu.ADLPingGu;
                string[] adlpgArry = new string[4];
                if (!string.IsNullOrEmpty(strADLPingGu))
                {
                    adlpgArry = strADLPingGu.Split('#');
                }
                #endregion
                //入科时间 获取 Patientinfo[7]
                string select = @"select DISTINCT(b.PATIENT_ID),'" + Patientinfo[7] + "' AS IN_DEPARTMENT_DATE  , '" + StringHelper.strReplace(ps.JiBenXinXi.RuYuanShiJian) + @"' AS IN_DATE,'" + StringHelper.strReplace(ps.JiBenXinXi.RuYuanFangShi) + @"' AS MODE,'" + StringHelper.strReplace(ps.JiBenXinXi.RuYuanZhenDuan) + @"' AS DIAGNOSE,'" + StringHelper.strReplace(ps.JiBenXinXi.JiGuan) + @"' AS NATIVE_PLACE,
'" + StringHelper.strReplace(ps.JiBenXinXi.WenHuaChengDu) + @"' AS EDUCATION,'" + StringHelper.strReplace(ps.JiBenXinXi.ZhiYe) + @"' AS JOB,'" + StringHelper.strReplace(ps.JiBenXinXi.HunYin) + @"' AS MARRIAGE,'" + StringHelper.strReplace(ps.JiBenXinXi.MinZu) + @"' AS NATIONALS,'" + StringHelper.strReplace(ps.JiBenXinXi.LianXiRen) + @"' AS LINKMAN,
'" + StringHelper.strReplace(ps.JiBenXinXi.YuHuanZheGuanXi) + @"' AS PATIENT_RELATION,'" + StringHelper.strReplace(ps.JiBenXinXi.LianXiDianHua) + @"' AS PHONE,'" + StringHelper.strReplace(ps.JiBenXinXi.T) + @"' AS TEMPERATURE,'" + StringHelper.strReplace(ps.JiBenXinXi.P) + @"' AS PULSE,'" + StringHelper.strReplace(ps.JiBenXinXi.R) + @"' AS BREATHING,
'" + StringHelper.strReplace(ps.JiBenXinXi.BP) + @"' AS BLOOD_PRESSURE1,'" + StringHelper.strReplace(ps.JiBenXinXi.BPText) + @"' AS BLOOD_PRESSURE2,'" + StringHelper.strReplace(ps.JiBenXinXi.TiZhong) + @"' AS WEIGHT,'" + StringHelper.strReplace(ps.JiBenXinXi.ShenGao) + @"' AS HEIGHT,

'" + StringHelper.strReplace(ps.TiZhengXinXi.ShenZhi) + @"' AS MIND,'" + StringHelper.strReplace(ps.TiZhengXinXi.ShenZhiText) + @"' AS MIND_OTHER,

( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.ManBingShi) + @"',1,1) WHEN 0 THEN 0 ELSE 1 END ) AS SLOW_HISTORY1,( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.ManBingShi) + @"',3,1) WHEN 0 THEN 0 ELSE 1 END ) AS SLOW_HISTORY2,( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.ManBingShi) + @"',5,1) WHEN 0 THEN 0 ELSE 1 END ) AS SLOW_HISTORY3,( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.ManBingShi) + @"',7,1) WHEN 0 THEN 0 ELSE 1 END ) AS SLOW_HISTORY4,( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.ManBingShi) + @"',9,1) WHEN 0 THEN 0 ELSE 1 END ) AS SLOW_HISTORY5,
'" + StringHelper.strReplace(ps.TiZhengXinXi.ManBingShiText) + @"' AS SLOW_HISTORY6,

'" + StringHelper.strReplace(ps.TiZhengXinXi.ShouShuShi) + @"' AS OPERATION_HISTORY,

'" + StringHelper.strReplace(ps.TiZhengXinXi.ShouShuShiText) + @"' AS OPERATION_HISTORY_OTHER,

( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.ShiLi) + @"',1,1) WHEN 0 THEN 0 ELSE 1 END ) AS VISION1,( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.ShiLi) + @"',3,1) WHEN 0 THEN 0 ELSE 1 END ) AS VISION2,( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.ShiLi) + @"',5,1) WHEN 0 THEN 0 ELSE 1 END ) AS VISION3,( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.ShiLi) + @"',7,1) WHEN 0 THEN 0 ELSE 1 END ) AS VISION4,( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.ShiLi) + @"',9,1) WHEN 0 THEN 0 ELSE 1 END ) AS VISION5,( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.ShiLi) + @"',11,1) WHEN 0 THEN 0 ELSE 1 END ) AS VISION6,( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.ShiLi) + @"',13,1) WHEN 0 THEN 0 ELSE 1 END ) AS VISION7,( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.ShiLi) + @"',15,1) WHEN 0 THEN 0 ELSE 1 END ) AS VISION8,
'" + StringHelper.strReplace(ps.TiZhengXinXi.ShiLiText) + @"' AS VISION9,

( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.TingLi) + @"',1,1) WHEN 0 THEN 0 ELSE 1 END ) AS HEARING1,( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.TingLi) + @"',3,1) WHEN 0 THEN 0 ELSE 1 END ) AS HEARING2,( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.TingLi) + @"',5,1) WHEN 0 THEN 0 ELSE 1 END ) AS HEARING3,( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.TingLi) + @"',7,1) WHEN 0 THEN 0 ELSE 1 END ) AS HEARING4,( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.TingLi) + @"',9,1) WHEN 0 THEN 0 ELSE 1 END ) AS HEARING5,( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.TingLi) + @"',11,1) WHEN 0 THEN 0 ELSE 1 END ) AS HEARING6,( CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.TingLi) + @"',13,1) WHEN 0 THEN 0 ELSE 1 END ) AS HEARING7,
'" + StringHelper.strReplace(ps.TiZhengXinXi.TingLiText) + @"' AS HEARING8,

'" + StringHelper.strReplace(ps.TiZhengXinXi.PiFu) + @"' AS SKIN,'" + StringHelper.strReplace(ps.TiZhengXinXi.PiFuText) + @"' AS SKIN_OTHER,
(CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.GuoMinShi) + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS ALLERGY_HISTORY,(CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.GuoMinShi) + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS ALLERGY_HISTORY_MEDICINE,
(CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.GuoMinShi) + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS ALLERGY_HISTORY_FOOD,(CASE SUBSTRING('" + StringHelper.strReplace(ps.TiZhengXinXi.GuoMinShi) + @"',7,1) WHEN 0 THEN 0 ELSE 1 END) AS ALLERGY_HISTORY_OTHER,
'" + StringHelper.strReplace(ps.TiZhengXinXi.GuoMinShiYaoWu) + @"' AS gmsyw,'" + StringHelper.strReplace(ps.TiZhengXinXi.GuoMinShiShiWu) + @"' AS gmssw,'" + StringHelper.strReplace(ps.TiZhengXinXi.GuoMinShiQiTa) + @"' AS gmsqt,

'" + StringHelper.strReplace(ps.SheHuiPingGu.ShiYu) + @"' AS DIET_APPETITE,'" + StringHelper.strReplace(ps.SheHuiPingGu.FangShi) + @"' AS DIET_MOTHOD,

( CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.HuoDong) + @"',1,1) WHEN 0 THEN 0 ELSE 1 END ) AS ACTIVITY1,( CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.HuoDong) + @"',3,1) WHEN 0 THEN 0 ELSE 1 END ) AS ACTIVITY2,( CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.HuoDong) + @"',5,1) WHEN 0 THEN 0 ELSE 1 END ) AS ACTIVITY3,( CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.HuoDong) + @"',7,1) WHEN 0 THEN 0 ELSE 1 END ) AS ACTIVITY4,( CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.HuoDong) + @"',9,1) WHEN 0 THEN 0 ELSE 1 END ) AS ACTIVITY5,( CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.HuoDong) + @"',11,1) WHEN 0 THEN 0 ELSE 1 END ) AS ACTIVITY6,( CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.HuoDong) + @"',13,1) WHEN 0 THEN 0 ELSE 1 END ) AS ACTIVITY7,'"+ ps.SheHuiPingGu.HuoDongText + @"' AS ACTIVITY7_Other,

'" + StringHelper.strReplace(ps.SheHuiPingGu.ShuiMian) + @"' AS SLEEP,'" + StringHelper.strReplace(ps.SheHuiPingGu.PaiBian) + @"' AS DEFECATION,
'" + StringHelper.strReplace(ps.SheHuiPingGu.PaiNiao) + @"' AS MICTURITION,'" + StringHelper.strReplace(ps.SheHuiPingGu.XiYan) + @"' AS SMOKE,'" + StringHelper.strReplace(ps.SheHuiPingGu.XiYanZhi) + @"' AS SMOKING_COUNTS_PER_DAY,'" + StringHelper.strReplace(ps.SheHuiPingGu.XiYanNian) + @"' AS SMOKE_YEAR,
'" + StringHelper.strReplace(ps.SheHuiPingGu.YinJiu) + @"' AS DRINK,'" + StringHelper.strReplace(ps.SheHuiPingGu.YinJiuMl) + @"' AS DRINK_ML,'" + StringHelper.strReplace(ps.SheHuiPingGu.YinJiuNian) + @"' AS DRINK_YEAR,'" + StringHelper.strReplace(ps.SheHuiPingGu.TengTong) + @"' AS PAIN,'" + StringHelper.strReplace(ps.SheHuiPingGu.XinLi) + @"' AS IN_MIND,'" + StringHelper.strReplace(ps.SheHuiPingGu.XinLiText) + @"' AS IN_MIND_OTHER,
(CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.JuZhuZhuangKuang) + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS LIVING_CONDITION1,(CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.JuZhuZhuangKuang) + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS LIVING_CONDITION2,
(CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.JuZhuZhuangKuang) + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS LIVING_CONDITION3,(CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.JuZhuZhuangKuang) + @"',7,1) WHEN 0 THEN 0 ELSE 1 END) AS LIVING_CONDITION4,
(CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.JuZhuZhuangKuang) + @"',9,1) WHEN 0 THEN 0 ELSE 1 END) AS LIVING_CONDITION5,(CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.JuZhuZhuangKuang) + @"',11,1) WHEN 0 THEN 0 ELSE 1 END) AS LIVING_CONDITION6,'" + StringHelper.strReplace(ps.SheHuiPingGu.JuZhuZhuangKuangText) + @"' AS LIVING_CONDITION_OTHER,
'" + StringHelper.strReplace(ps.SheHuiPingGu.ZongJiaoXinYang) + @"' AS RELIGIOUS_BELIEF,'" + StringHelper.strReplace(ps.SheHuiPingGu.ZongJiaoXinYangText) + @"' AS RELIGIOUS_BELIEF_OTHER,

( CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.FeiYongLaiYuan) + @"',1,1) WHEN 0 THEN 0 ELSE 1 END ) AS COST_SOURCES1,( CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.FeiYongLaiYuan) + @"',3,1) WHEN 0 THEN 0 ELSE 1 END ) AS COST_SOURCES2,( CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.FeiYongLaiYuan) + @"',5,1) WHEN 0 THEN 0 ELSE 1 END ) AS COST_SOURCES3,( CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.FeiYongLaiYuan) + @"',7,1) WHEN 0 THEN 0 ELSE 1 END ) AS COST_SOURCES4,( CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.FeiYongLaiYuan) + @"',9,1) WHEN 0 THEN 0 ELSE 1 END ) AS COST_SOURCES5,( CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.FeiYongLaiYuan) + @"',11,1) WHEN 0 THEN 0 ELSE 1 END ) AS COST_SOURCES6,
'" + StringHelper.strReplace(ps.SheHuiPingGu.FeiYongLaiYuanText) + @"' AS COST_SOURCES7,

(CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.TeShuRenQun) + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS SPECIAL_GROUP1,(CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.TeShuRenQun) + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS SPECIAL_GROUP2,
(CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.TeShuRenQun) + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS SPECIAL_GROUP3,(CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.TeShuRenQun) + @"',7,1) WHEN 0 THEN 0 ELSE 1 END) AS SPECIAL_GROUP4,
(CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.TeShuRenQun) + @"',9,1) WHEN 0 THEN 0 ELSE 1 END) AS SPECIAL_GROUP5,(CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.TeShuRenQun) + @"',11,1) WHEN 0 THEN 0 ELSE 1 END) AS SPECIAL_GROUP6,
(CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.TeShuRenQun) + @"',17,1) WHEN 0 THEN 0 ELSE 1 END) AS SPECIAL_GROUP7,(CASE SUBSTRING('" + StringHelper.strReplace(ps.SheHuiPingGu.TeShuRenQun) + @"',19,1) WHEN 0 THEN 0 ELSE 1 END) AS SPECIAL_GROUP8,

'" + StringHelper.strReplace(ps.DieDaoYaChuangADLFengXianPingGu.DieDaoPingGuFenShu) + @"' AS FALL_RISK_ASSESSMENT_SCORE,'" + ddpgArry[0] + "' AS FALL_RISK_ASSESSMENT_ITEM1, '" + ddpgArry[1] + @"' AS FALL_RISK_ASSESSMENT_ITEM2,
'" + StringHelper.strReplace(ps.DieDaoYaChuangADLFengXianPingGu.YaChuangPingGuFenShu) + @"' AS PRESSURE_RISK_ASSESSMENT_SCORE, '" + ycpgArry[0] + @"' AS PRESSURE_RISK_ASSESSMENT_ITEM1,
'" + ycpgArry[1] + "'AS PRESSURE_RISK_ASSESSMENT_ITEM2,'" + ycpgArry[2] + @"' AS PRESSURE_RISK_ASSESSMENT_ITEM3,
'" + ycpgArry[3] + "' AS PRESSURE_RISK_ASSESSMENT_ITEM4,'" + ycpgArry[4] + @"' AS PRESSURE_RISK_ASSESSMENT_ITEM5,
'" + StringHelper.strReplace(ps.DieDaoYaChuangADLFengXianPingGu.ADLPingGuFenShu) + @"' AS ADL_SCORE,

'" + adlpgArry[0] + @"' AS ADL_SCORE_ITEM1,
'" + adlpgArry[1] + @"' AS ADL_SCORE_ITEM2,
'" + adlpgArry[2] + @"' AS ADL_SCORE_ITEM3,
'" + adlpgArry[3] + @"' AS ADL_SCORE_ITEM4,

'" + StringHelper.strReplace(ps.ChuYuanPingGu.ChuYuanRiQi) + @"' AS OUT_DATE,'" + StringHelper.strReplace(ps.ChuYuanPingGu.ChuYuanZhenDuan) + @"' AS DISCHARGE_DIAGNOSIS,'" + StringHelper.strReplace(ps.ChuYuanPingGu.ADLPingFen) + @"' AS ADL_SCORE_OUT,
(CASE SUBSTRING('" + StringHelper.strReplace(ps.ChuYuanPingGu.ZiLiNengLi) + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS ADL_SCORE_ITEM_OUT1,(CASE SUBSTRING('" + StringHelper.strReplace(ps.ChuYuanPingGu.ZiLiNengLi) + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS ADL_SCORE_ITEM_OUT2,
(CASE SUBSTRING('" + StringHelper.strReplace(ps.ChuYuanPingGu.ZiLiNengLi) + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS ADL_SCORE_ITEM_OUT3,(CASE SUBSTRING('" + StringHelper.strReplace(ps.ChuYuanPingGu.ZiLiNengLi) + @"',7,1) WHEN 0 THEN 0 ELSE 1 END) AS ADL_SCORE_ITEM_OUT4,
(CASE SUBSTRING('" + StringHelper.strReplace(ps.ChuYuanPingGu.ChuYuanHouQuXiang) + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS WHERE_AFTER_DISCHARGE1,(CASE SUBSTRING('" + StringHelper.strReplace(ps.ChuYuanPingGu.ChuYuanHouQuXiang) + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS WHERE_AFTER_DISCHARGE2,
(CASE SUBSTRING('" + StringHelper.strReplace(ps.ChuYuanPingGu.ChuYuanHouQuXiang) + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS WHERE_AFTER_DISCHARGE3,(CASE SUBSTRING('" + StringHelper.strReplace(ps.ChuYuanPingGu.ChuYuanHouQuXiang) + @"',7,1) WHEN 0 THEN 0 ELSE 1 END) AS WHERE_AFTER_DISCHARGE4,
(CASE SUBSTRING('" + StringHelper.strReplace(ps.ChuYuanPingGu.ChuYuanHouQuXiang) + @"',9,1) WHEN 0 THEN 0 ELSE 1 END) AS WHERE_AFTER_DISCHARGE5,'" + (!Base.ESSwitch.Equals("on")?StringHelper.strReplace(ps.DieDaoYaChuangADLFengXianPingGu.RuYuanHuShiQianMing):"") + @"' AS NURSE_SIGN1,'" + (!Base.ESSwitch.Equals("on")?StringHelper.strReplace(ps.ChuYuanPingGu.ChuYuanHuShiQianMing):"") + @"' AS NURSE_SIGN2,
'" + StringHelper.strReplace(ps.ChuYuanPingGu.ChuYuanRiQi) + @"' AS NURSE_SIGN1_DATE,
b.PATIENT_NAME,b.SEX,b.AGE,b.NURSE_CELL_NAME,b.DEPARTMENT_NAME,b.BED_NO,b.PATIENT_ID ";
                if (image1!=""&&image2!="")
                {
                    select+=@",'"+image1+"' AS ElectricSignBase641,'"+image2+"' AS ElectricSignBase642  from NursingFormRecord(NOLOCK) AS a left join V_YDHL_PATIENT(NOLOCK) AS b on a.PatientId=b.PATIENT_ID and a.VisitId=b.VISIT_ID where a.PatientId  = '" + Patientinfo[0] + "' and a.VisitId='" + Patientinfo[1] + "' and a.FormId='" + FormId + "'";
                }
                else if (image1!=""&&image2=="")
                {
                    select += @",'"+image1+"' AS ElectricSignBase641 from NursingFormRecord(NOLOCK) AS a left join V_YDHL_PATIENT(NOLOCK) AS b on a.PatientId=b.PATIENT_ID and a.VisitId=b.VISIT_ID where a.PatientId  = '" + Patientinfo[0] + "' and a.VisitId='" + Patientinfo[1] + "' and a.FormId='" + FormId + "'";
                }
                else if (image1 == "" && image2 != "")
                {
                    select += @",'" + image2 + "' AS ElectricSignBase642 from NursingFormRecord(NOLOCK) AS a left join V_YDHL_PATIENT(NOLOCK) AS b on a.PatientId=b.PATIENT_ID and a.VisitId=b.VISIT_ID where a.PatientId  = '" + Patientinfo[0] + "' and a.VisitId='" + Patientinfo[1] + "' and a.FormId='" + FormId + "'";
                }
                else
                {
                    select += @" from NursingFormRecord(NOLOCK) AS a left join V_YDHL_PATIENT(NOLOCK) AS b on a.PatientId=b.PATIENT_ID and a.VisitId=b.VISIT_ID where a.PatientId  = '" + Patientinfo[0] + "' and a.VisitId='" + Patientinfo[1] + "' and a.FormId='" + FormId + "'";
                }

                axGRPrintViewer1.ShowPrintDlg = false;//设置 ShowPrintDlg 属性，让点击工具栏中的打印按钮时不显示打印对话框
                try
                {
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + @"\GRFModel\Ydhl_GRF\住院患者护理评估单.grf"))
                    {
                        Report.LoadFromFile(System.Windows.Forms.Application.StartupPath + @"\GRFModel\Ydhl_GRF\住院患者护理评估单.grf");
                    }
                    else
                    {
                        Report.LoadFromFile(@"../../Ydhl_GRF/住院患者护理评估单.grf");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("加载住院患者护理评估单失败，请检查文件Ydhl_GRF/住院患者护理评估单.grf是否存在");
                    WriteLog.WriteLogString(ex.Message + ".  加载住院患者护理评估单失败，请检查文件Ydhl_GRF/住院患者护理评估单.grf是否存在");
                }
                Report.ConnectionString = Utility.GetDatabaseConnectionString();
                Report.DetailGrid.Recordset.QuerySQL = select;
                axGRPrintViewer1.Report = Report;

                axGRPrintViewer1.Start();
            }
            else if (ret.Code == 2)
            {
                string select = @"select '' AS IN_DEPARTMENT_DATE,
'' AS NURSE_SIGN1_DATE,
b.PATIENT_NAME,b.SEX,b.AGE,b.NURSE_CELL_NAME,b.DEPARTMENT_NAME,b.BED_NO,b.PATIENT_ID,
'' AS IN_DATE,'' AS MODE,'' AS DIAGNOSE,'' AS NATIVE_PLACE,
'' AS EDUCATION,'' AS JOB,'' AS MARRIAGE,'' AS NATIONALS,'' AS LINKMAN,
'' AS PATIENT_RELATION,'' AS PHONE,'' AS TEMPERATURE,'' AS PULSE,'' AS BREATHING,
'' AS BLOOD_PRESSURE1,'' AS BLOOD_PRESSURE2,'' AS WEIGHT,'' AS HEIGHT,
'' AS MIND,'' AS MIND_OTHER,'' AS SLOW_HISTORY,'' AS SLOW_HISTORY_OTHER,
'' AS OPERATION_HISTORY,'' AS OPERATION_HISTORY_OTHER,'' AS VISION,'' AS VISION_OTHER,
'' AS HEARING,'' AS HEARING_OTHER,'' AS SKIN,'' AS SKIN_OTHER,
'' AS ALLERGY_HISTORY,'' AS ALLERGY_HISTORY_MEDICINE,
'' AS ALLERGY_HISTORY_FOOD,'' AS ALLERGY_HISTORY_OTHER,
'' AS DIET_APPETITE,'' AS DIET_MOTHOD,'' AS ACTIVITY,'' AS SLEEP,'' AS DEFECATION,
'' AS MICTURITION,'' AS SMOKE,'' AS SMOKING_COUNTS_PER_DAY,'' AS SMOKE_YEAR,
'' AS DRINK,'' AS DRINK_ML,'' AS DRINK_YEAR,'' AS PAIN,'' AS IN_MIND,'' AS IN_MIND_OTHER,
'' AS LIVING_CONDITION1,'' AS LIVING_CONDITION2,
'' AS LIVING_CONDITION3,'' AS LIVING_CONDITION4,
'' AS LIVING_CONDITION5,'' AS LIVING_CONDITION6,'' AS LIVING_CONDITION_OTHER,
'' AS RELIGIOUS_BELIEF,'' AS RELIGIOUS_BELIEF_OTHER,'' AS COST_SOURCES,'' AS COST_SOURCES_OTHER,
'' AS SPECIAL_GROUP1,'' AS SPECIAL_GROUP2,
'' AS SPECIAL_GROUP3,'' AS SPECIAL_GROUP4,
'' AS SPECIAL_GROUP5,'' AS SPECIAL_GROUP6,
'' AS SPECIAL_GROUP7,'' AS SPECIAL_GROUP8,
'' AS FALL_RISK_ASSESSMENT_SCORE,
'' AS FALL_RISK_ASSESSMENT_ITEM1,'' AS FALL_RISK_ASSESSMENT_ITEM2,
'' AS PRESSURE_RISK_ASSESSMENT_SCORE,'' AS PRESSURE_RISK_ASSESSMENT_ITEM1,
'' AS PRESSURE_RISK_ASSESSMENT_ITEM2,'' AS PRESSURE_RISK_ASSESSMENT_ITEM3,
'' AS PRESSURE_RISK_ASSESSMENT_ITEM4,'' AS PRESSURE_RISK_ASSESSMENT_ITEM5,
'' AS ADL_SCORE,
'' AS ADL_SCORE_ITEM1,'' AS ADL_SCORE_ITEM2,
'' AS ADL_SCORE_ITEM3,'' AS ADL_SCORE_ITEM4,
'' AS OUT_DATE,'' AS DISCHARGE_DIAGNOSIS,'' AS ADL_SCORE_OUT,
'' AS ADL_SCORE_ITEM_OUT1,'' AS ADL_SCORE_ITEM_OUT2,
'' AS ADL_SCORE_ITEM_OUT3,'' AS ADL_SCORE_ITEM_OUT4,
'' AS WHERE_AFTER_DISCHARGE1,'' AS WHERE_AFTER_DISCHARGE2,
'' AS WHERE_AFTER_DISCHARGE3,'' AS WHERE_AFTER_DISCHARGE4,
'' AS WHERE_AFTER_DISCHARGE5,'' AS NURSE_SIGN1,'' AS NURSE_SIGN2,'' AS ElectricSignBase641,'' AS ElectricSignBase642
from V_YDHL_PATIENT(NOLOCK) AS b  where b.Patient_Id  = '" + Patientinfo[0] + "' ";

                axGRPrintViewer1.ShowPrintDlg = false;//设置 ShowPrintDlg 属性，让点击工具栏中的打印按钮时不显示打印对话框
                try
                {
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + @"\GRFModel\Ydhl_GRF\住院患者护理评估单.grf"))
                    {
                        Report.LoadFromFile(System.Windows.Forms.Application.StartupPath + @"\GRFModel\Ydhl_GRF\住院患者护理评估单.grf");
                    }
                    else
                    {
                        Report.LoadFromFile(@"../../Ydhl_GRF/住院患者护理评估单.grf");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("加载住院患者护理评估单失败，请检查文件Ydhl_GRF/住院患者护理评估单.grf是否存在");
                    WriteLog.WriteLogString(ex.Message + ".  加载住院患者护理评估单失败，请检查文件Ydhl_GRF/住院患者护理评估单.grf是否存在");
                }
                Report.DetailGrid.Recordset.QuerySQL = select;
                axGRPrintViewer1.Report = Report;
                axGRPrintViewer1.Start();
            }
        }

        private void NursingFormPrint_Load(object sender, EventArgs e)
        {

        }
        private void axGRPrintViewer1_CloseButtonClick(object sender, System.EventArgs e)
        {
            Close();
        }

        private void axGRPrintViewer1_CustomButtonClick_1(object sender, Axgregn6Lib._IGRPrintViewerEvents_CustomButtonClickEvent e)
        {
            //响应自定义按钮点击，根据BtnID完成对应的任务
            System.Windows.Forms.MessageBox.Show(System.String.Format("执行自定义按钮任务, BtnID={0}", e.btnID), "CustomButtonClick"
                , System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
        }
    }
}
